<%@page contentType="text/html;charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>生成订单 - 当当网</title>
		<link href="<%=request.getContextPath()%>/css/login.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/page_bottom.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.3.js"></script>
		<script type="text/javascript">
			jQuery(function(){
				//加载地址
				jQuery.post("<%=request.getContextPath()%>/order/getAddress.do", {}, function(msg){
					if(msg){
						var json = eval("(" + msg + ")");
						var address = "<option value='-1'>填写新地址</option>";
						var selectedAddress = jQuery("#selectedAddress").val();
						for(var i = 0; i < json.length; i++){
							if(json.id == selectedAddress){
								address += "<option value='" + json.id + "' selected='selected'>" + json.receive_name + "</option>";							
							} else {
								address += "<option value='" + json.id + "'>" + json.receive_name + "</option>";
							}
						}
						jQuery("#address").empty().append(address);
					} else {
						var address = "<option value='-1'>填写新地址</option>";
						jQuery("#address").empty().append(address);
					}
				});
				
				jQuery("#address").change(function(){
					var value = jQuery("#address").val();
					jQuery("#selectedAddress").val(value);
					if(value == -1){
						$("#id").val("").removeAttr("readonly");
						$("#receiveName").val("").removeAttr("readonly");
						$("#fullAddress").val("").removeAttr("readonly");
						$("#postalCode").val("").removeAttr("readonly");
						$("#phone").val("").removeAttr("readonly");
						$("#mobile").val("").removeAttr("readonly");
						return;
					}
					jQuery.post("<%=request.getContextPath()%>/order/getAddressById.do", {"id": value}, function(msg){
						if(msg){
							var json = eval("(" + msg + ")");
							$("#receiveName").val(json.receive_name).attr("readonly","readonly");
							$("#fullAddress").val(json.full_address).attr("readonly","readonly");
							$("#postalCode").val(json.postalCode).attr("readonly","readonly");
							$("#phone").val(json.phone).attr("readonly","readonly");
							$("#mobile").val(json.mobile).attr("readonly","readonly");
						} else {
							$("#receiveName").val("");
							$("#fullAddress").val("");
							$("#postalCode").val("");
							$("#phone").val("");
							$("#mobile").val("");
						}
					});
				});
				
				jQuery("#f").submit(submitForm);
			});
			
			function submitForm(){
				//对表单数据进行验证
				
				jQuery("#f").submit();
			}
		</script>
	</head>
	<body>
		<%@include file="../common/head1.jsp"%>
		<div class="login_step">
			生成订单骤: 1.确认订单 &gt;
			<span class="red_bold"> 2.填写送货地址</span> &gt; 3.订单成功
		</div>
		<div class="fill_message">
			<p>
				选择地址：
				<select id="address">
				</select>
			</p>
			<form name="ctl00" method="post" action="<%=request.getContextPath()%>/order/orderSuccess.do" id="f">
				<input type="hidden" name="selectedAddress" id="selectedAddress"/>
				<table class="tab_login">
					<tr>
						<td valign="top" class="w1">
							收件人姓名：
						</td>
						<td>
							<input type="text" class="text_input" name="receive_name" id="receiveName"/>
							<div class="text_left" id="nameValidMsg">
								<p>请填写有效的收件人姓名</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							收件人详细地址：
						</td>
						<td>
							<input type="text" name="full_address" class="text_input" id="fullAddress" />
							<div class="text_left" id="addressValidMsg">
								<p>请填写有效的收件人的详细地址</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							邮政编码：
						</td>
						<td>
							<input type="text" class="text_input" name="postal_code" id="postalCode" />
							<div class="text_left" id="codeValidMsg">
								<p>请填写有效的收件人的邮政编码</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							电话：
						</td>
						<td>
							<input type="text" class="text_input" name="phone" id="phone" />
							<div class="text_left" id="phoneValidMsg">
								<p>请填写有效的收件人的电话</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							手机：
						</td>
						<td>
							<input type="text" class="text_input" name="mobile" id="mobile" />
							<div class="text_left" id="mobileValidMsg">
								<p>请填写有效的收件人的手机</p>
							</div>
						</td>
					</tr>
				</table>

				<div class="login_in">
					<a href="<%=request.getContextPath()%>/order/orderInfo.do">
						<input id="btnClientRegister" class="button_1" name="submit" type="button" value="取消"/>
					</a>
					<input id="btnClientRegister" class="button_1" name="submit" type="submit" value="下一步"/>
				</div>
			</form>
		</div>
		<%@include file="../common/foot1.jsp"%>
	</body>
</html>
